package com.learn.util.log;

/*import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;*/

import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

/**
 * 
 * @ProjectName：platform-log
 * @ClassName：LoggerFactory
 * @Description：日志工厂类
 * @author: 任瑞修
 * @date: 2013-11-11 上午10:30:28
 *
 */
public class LoggerFactory {
//public class LoggerFactory implements ApplicationContextAware {
	
	private static final Hashtable<String, Logger> loggerCache = new Hashtable<String, Logger>();
	
	/**
	 * 
	 * @Description：获取日志输出类实例
	 * @author: 任瑞修
	 * @date: 2013-11-11 上午10:30:38
	 * @param clazz
	 * @return
	 */
	public static Logger getLogger(final Class<?> clazz) {
		org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(clazz.getName());
		String loggerName = logger.getName();
		if(loggerCache.containsKey(loggerName)) {
			return loggerCache.get(loggerName);
		} else {
			Logger platformLogger = new PlatformLogger(logger);
			loggerCache.put(loggerName, platformLogger);
			
			return platformLogger;
		}
	}
	
	/**
	 * 
	 * @Description：分发日志事件
	 * @author: 任瑞修
	 * @date: 2013-11-11 上午11:56:00
	 * @param event
	 */
	public static void dispatchListener(LoggingEvent event) {
		/*if(CollectionUtils.isNotEmpty(logListeners)) {
			for(LogListener listener : logListeners) {
				listener.log(event);
			}
		}*/
	}

	/**
	 * 日志事件监听器集
	 */
	private static List<LogListener> logListeners = null;
	
	/*@Override
	public void setApplicationContext(ApplicationContext context) throws BeansException {
		logListeners = new ArrayList<LogListener>(context.getBeansOfType(LogListener.class).values());
	}*/
}
